package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.adapters.BaoXianJiFenAdapter;
import com.lc.afbx.conn.GetApiBaoXianJiFen;
import com.zcx.helper.app.AppCallBack;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/20.
 */
public class IntegralActivity extends BaseActivity implements View.OnClickListener {


    private TextView integral;
    private ListView integral_lv;

    private List<GetApiBaoXianJiFen.Detail> lists = new ArrayList<>();
    private BaoXianJiFenAdapter adapter;

    private GetApiBaoXianJiFen getApiBaoXianJiFen = new GetApiBaoXianJiFen(new AsyCallBack<GetApiBaoXianJiFen.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiBaoXianJiFen.Info info) throws Exception {

            lists.addAll(info.data.detailList);

            integral.setText(info.data.integral);//获取设置积分

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);
        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_integral);

//        findViewById(R.id.integral_rule_rl).setOnClickListener(this);

        View header = getLayoutInflater().inflate(R.layout.header_integral, null);
        BaseApplication.ScaleScreenHelper.loadView((ViewGroup) header);

        integral = ((TextView) header.findViewById(R.id.integral));

        integral_lv = (ListView) findViewById(R.id.integral_lv);

        integral_lv.addHeaderView(header, null, false);

        integral_lv.setDivider(null);

        integral_lv.setAdapter(adapter = new BaoXianJiFenAdapter(context, lists));

        setAppCallBack(new RrfreshIntegralCallback());

        new RrfreshIntegralCallback().refreshIntegral();

    }


    @Override
    public void onClick(View view) {


        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.integral_rule_rl:

                startActivity(new Intent(this, IntegralRuleActivity.class));
                break;

            case R.id.header_integral_bt:

                startActivity(new Intent(this, IntegralExchangeActivity.class));
                break;

        }


    }


    public class RrfreshIntegralCallback implements AppCallBack {

        public void refreshIntegral() {


            lists.clear();

            getApiBaoXianJiFen.uid = BaseApplication.BasePreferences.readUserId();
            getApiBaoXianJiFen.execute(IntegralActivity.this);
        }
    }


}
